# -*- coding: utf-8 -*-
# #####################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 OpenERP s.a. (<http://openerp.com>).
# Copyright (C) 2013 INIT Tech Co., Ltd (http://init.vn).
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
######################################################################
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
import time

from osv import fields, osv
from tools.translate import _
import decimal_precision as dp
import netsvc


class wizard_print_send_mail(osv.osv_memory):
    _name = 'wizard.print.send.mail'
    _columns = {
        'lines' : fields.one2many('wizard.print.send.mail.line', 'order_id', 'Lines'),
                }
    
    def print_report(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        datas = {'ids': context.get('active_ids', [])}

        res = self.read(cr, uid, ids, ['lines'],
                        context=context)
        res = res and res[0] or {}
        datas['form'] = res
        datas['model'] = 'wizard.print.send.mail'
        return {
            'type': 'ir.actions.report.xml',
            'report_name': 'product.report',
            'datas': datas,
        } 

wizard_print_send_mail()

class wizard_print_send_mail_line(osv.osv_memory):
    _name = 'wizard.print.send.mail.line'
    _columns = {
        'order_id': fields.many2one('wizard.print.send.mail', 'Order'),
        'company_id': fields.many2one('res.company', 'Company'),
        'user_id': fields.many2one('res.users', 'User'),
        'user_email': fields.char('Email', size=64),
                }
    
    def onchange_user_id(self, cr, uid, ids, user_id):
        v = {}
        res_user = self.pool.get('res.users')
        if user_id:
            user = res_user.browse(cr, uid, user_id)
            v['user_email'] = user.user_email
            v['name'] = user.user_email
            v['company_id'] = user.company_id.id
        return {'value': v}    

wizard_print_send_mail_line()